<template>
	<view>
		<view class="Describe">
			<view class="Describe-title1">请您重新编辑您的密码</view>
			<view class="Describe-title2">建议您的新密码以简单好记为标准</view>
		</view>
		<!-- 账号密码输入框 -->
		<view class="form">
			<view class="username">
				<input placeholder="新密码" type="number" v-model="newpass" placeholder-style="color: #d7d7d9;" />
			</view>
			<view class="password">
				<input placeholder="确认新密码" type="number" v-model="newpass2" placeholder-style="color: #d7d7d9;" />
			</view>
			<view class="btn" @click="submit">确认修改</view>
		</view>
	</view>

</template>

<script>
	// import md5 from "../../../common/SDK/md5.min.js";
	export default {
		data() {
			return {
				password: '',
				newpass: '',
				newpass2: '',
				userid: '',
				encrypt:''
			}
		},
		onShow() {

		},
		onLoad(options) {
			console.log(options)
			if (options && options.userid != undefined && options.userid != '') {
				this.userid = options.userid;
			}
			if (options && options.encrypt != undefined && options.encrypt != '') {
				this.encrypt = options.encrypt;
			}
		},
		computed: {

		},
		methods: {
			submit() {
				if (this.newpass.replace(/(^\s*)|(\s*$)/g, "") == '') {
					uni.showToast({
						title: '请输入新密码',
						icon: "none"
					});
					return false;
				}
				if (this.newpass2.replace(/(^\s*)|(\s*$)/g, "") == '') {
					uni.showToast({
						title: '请确认密码',
						icon: "none"
					});
					return false;
				}
				if (this.userid.replace(/(^\s*)|(\s*$)/g, "") == '') {
					uni.showToast({
						title: '获取用户id失败,请重试',
						icon: "none",
						success: function() {
							setTimeout(function() {
								uni.navigateTo({
									url: '/pages/user/login/resetpasswd'
								})
							}, 2000)
						}
					});
					return false;
				}
				uni.showLoading({
					title: '提交中...'
				})
				let that=this;
				//访问接口获取验证码
				let data = this.initNewData();
				//位置类别
				data.location = 5267;
				data.newpass = this.newpass;
				data.newpass2 = this.newpass2;
				data.userid = this.userid;
				data.encrypt = this.encrypt;
				console.log(data)
				uni.request({
					url: this.baseConfig.serverURL + 'User/login/SetNewPasswordHandler.ashx', //检查更新的服务器地址
					data: data,
					method: "POST",
					header: {
						"content-type": "application/x-www-form-urlencoded" //"application/json"
					},
					success: (res) => {
						if (res.statusCode == 200) {
							if (!res.data.ret) {
								uni.hideLoading()
								uni.showToast({
									title: res.data.msg,
									icon: "none"
								});
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: "none",
									success: function() {
										setTimeout(function() {
											that.doLogout();
											uni.switchTab({
												url: '/pages/user/user'
											})
										}, 2000)
									}
								});
							}
						} else {
							uni.hideLoading()
							uni.showToast({
								title: '重置密码失败！',
								icon: "none"
							});
						}
					},
					fail: (res) => {
						uni.hideLoading()
						uni.showToast({
							title: '重置密码失败，可能已超时！',
							icon: "none"
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "../../../static/css/login.scss";

	.Describe {
		width: 80%;
		padding: 0 10%;
		margin: 40rpx auto;

		.Describe-title1 {
			font-size: 36rpx;
			color: #000000;
		}

		.Describe-title2 {
			font-size: 26rpx;
			color: #CCCCCC;
			margin-top: 10rpx;
		}
	}

	.form {
		.btn {
			font-size: 32rpx;
		}
	}

	.password {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;

		button {
			font-size: 28rpx;
			color: #5a90e7 !important;
			border: 1px solid #5a90e7;
			border-radius: 3px;
			padding: 14rpx 0px;
			width: 40%;
			text-align: center;
			line-height: 36rpx;
			background-color: #FFFFFF !important;

			&:after {
				border: none
			}

			&.active {
				background-color: #5a90e7;
				color: #fff;
			}
		}
	}

	.solution {
		position: fixed;
		bottom: 100rpx;
		font-size: 26rpx;
		color: #CCCCCC;
		width: 40%;
		left: 30%;

		image {
			width: 52rpx;
			height: 54rpx;
			vertical-align: middle;
		}
	}
</style>
